<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

if(!isset($_SESSION['user_id'])) {
	if ( $_POST ) {
		$login_user = ZUser::GetLogin($_POST['email'], $_POST['password']);
		if ( !$login_user ) {
			Session::Set('error', '登录失败');
			redirect(null);
		} else if ($INI['system']['emailverify'] 
				&& $login_user['enable']=='N'
				&& $login_user['secret']
				) {
			Session::Set('unemail', $_POST['email']);
			redirect(null);
		} else {
			Session::Set('user_id', $login_user['id']);
			ZLogin::Remember($login_user);
			ZUser::SynLogin($_POST['email'], $_POST['password']);
			redirect(null);
		}
	}
	$html = render('ajax_dialog_needlogin');
	json($html, 'dialog');
} else {
	if( $_GET['appkey'] == null || $_GET['appkey'] == '' ){
		Session::Set('error', '商户合作号为空');
		redirect(WEB_ROOT."/connect/share.php");
	}
	if( $_GET['remark'] == null || $_GET['remark'] == '' ){
		Session::Set('error', '发布的消息不能为空');
		redirect(WEB_ROOT."/connect/share.php");
	}else if( $_GET['mobile'] == null || $_GET['mobile'] == '' || !Utility::IsMobile($_GET['mobile']) ){
		Session::Set('error', '手机号码有误');
		redirect(WEB_ROOT."/connect/share.php");
	}
	
	// 适配
	$_POST = $_GET;
	$_GET['id'] = $_GET['appkey'];
	
	require_once(dirname(dirname(dirname(__FILE__))) . '/connect/buy.php');
//	redirect(WEB_ROOT."/team/buy.php?id={$_GET['appkey']}");
}